package com.zw.pdm.module.file.controller;

import com.zw.pdm.base.BaseController;
import com.zw.pdm.common.JsonResult;
import com.zw.pdm.entity.production.FileSheet;
import com.zw.pdm.module.basic.service.DictCommonService;
import com.zw.pdm.module.file.service.FileListService;
import com.zw.pdm.module.file.service.FileQueryService;
import com.zw.pdm.module.system.service.DeptService;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.zw.pdm.constant.Constant.GROUP_SPECTYPE;

/**
 * @author mayongfeng
 * @version 1.0.0
 * @ClassName CreateFileController.java
 * @Description TODO
 * @createTime 2020年12月12日 15:22:00
 */
@Controller
@RequiresPermissions("all")
@RequestMapping("file/query")
public class FileQueryController extends BaseController {
    @Autowired
    private DictCommonService dictCommonService;
    @Autowired
    private DeptService deptService;
    @Autowired
    private FileQueryService fileQueryService;
    @Autowired
    private FileListService fileListService;


    @GetMapping
    @RequiresPermissions(value = {"file:query:view"}, logical = Logical.OR)
    public String queryList(String proCode, Model model) {
        model.addAttribute("malTypes", dictCommonService.findDictByGroupName(GROUP_SPECTYPE));
        model.addAttribute("depts", deptService.findAllTopLevelDept());
        model.addAttribute("proCode", proCode);
        return "file/query/fileQueryList";
    }

    /** 存档列表 */
    @ResponseBody
    @PostMapping("/list")
    @RequiresPermissions(value = {"file:query:view"}, logical = Logical.OR)
    public JsonResult list(FileSheet fileSheet) {
        startPage();
        List<FileSheet> list = fileQueryService.findFileListQuery(fileSheet);
        return jsonResult(list);
    }

    /** 查看 */
    @GetMapping("/info/{id}")
    @RequiresPermissions(value = {"file:query:view"}, logical = Logical.OR)
    public String print(@PathVariable("id") Integer sheetId, Model model) {
        FileSheet fileSheet = fileListService.getfileListById(sheetId);
        model.addAttribute("process", fileListService.findVpBySheetId(sheetId));
        model.addAttribute("fileSheet", fileSheet);
        model.addAttribute("filePlan", fileListService.findFilePlanBySheetId(sheetId));
        return "file/query/filePrint";



    }


}
